import { reqGetDetailList,reqAddOrUpdateShopCart } from "@/api"
const state = {
    detailList:{}
}
const actions = {
    async getDetailList({commit},skuId){
        let result = await reqGetDetailList(skuId);
        if(result.code == 200){
            commit('GETDETAILLIST',result.data)
        }
    },
    async goShopCart({commit},{skuId,skuNum}){
            let result = await reqAddOrUpdateShopCart(skuId,skuNum);
            if(result.code == 200){
                return 'ok'
            }else{
                return Promise.reject(new Error('faile'))
            }
    }
}
const mutations = {
    GETDETAILLIST(state,detailList){
        state.detailList = detailList
    }
}
const getters = {
    categoryView(state){
        //在数据没有回来前先赋值为一个这样才能找到相应的属性
        return state.detailList.categoryView||{}
    },
    skuInfo(state){
        return state.detailList.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList
    },
}
export default {
    state,
    actions,
    mutations,
    getters
}